package com.javalong.affairs.activity;

import java.util.HashMap;
import java.util.Map;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import com.google.gson.reflect.TypeToken;
import com.javalong.affairs.R;
import com.javalong.affairs.constant.RequestKey;
import com.javalong.affairs.listener.BaseResponseListener;
import com.javalong.affairs.model.User;
import com.javalong.affairs.ui.TopTitle;
import com.javalong.affairs.utils.HttpUtils;
import com.javalong.affairs.utils.UrlUtils;
import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ContentView;
import com.lidroid.xutils.view.annotation.ViewInject;

@ContentView(R.layout.activity_updatepwd)
public class UpdatePwdActivity extends BaseActivity {
	@ViewInject(R.id.ui_toptitle)
	private TopTitle topTitle;
	@ViewInject(R.id.et_oldpwd)
	private EditText et_oldpwd;
	@ViewInject(R.id.et_newpwd)
	private EditText et_newpwd;
	@ViewInject(R.id.bt_update)
	private Button bt_update;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		ViewUtils.inject(this);
		topTitle.setOnLeftDrawableClick(this);
		bt_update.setOnClickListener(this);
	}

	@Override
	public void onClick(View v) {
		super.onClick(v);
		switch (v.getId()) {
		case R.id.bt_update:
			String url = UrlUtils.getUrl("User", "updatePassword");
			Map<String, Object> params = new HashMap<String, Object>();
			params.put(RequestKey.PASSWORDOLD, et_oldpwd.getText().toString());
			params.put(RequestKey.PASSWORD, et_newpwd.getText().toString());
			progressDialog.show();
			HttpUtils.post(url, params, new BaseResponseListener(
					new TypeToken<User>() {
					}.getType()) {
				@Override
				public void onSuccess(Object obj) {
					super.onSuccess(obj);
					progressDialog.dismiss();
					finish();
				}
			});
			break;

		default:
			break;
		}
	}
}
